<!--#
layout("/layouts/store.html"){
#-->
<script src="${base!}/assets/platform/vendor/ueditor/ueditor.config.js"></script>
<script src="${base!}/assets/platform/vendor/ueditor/ueditor.all.js"></script>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/store/video/cms" id="goBack" data-pjax><i class="ti-angle-left"></i>${msg['globals.button.back']}</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:700px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/store/video/cms/addDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label for="videoUrl" class="col-sm-2 control-label">上传视频</label>
                            <div class="col-sm-8">
                                <div id="queue"></div>
                                <div>
                                    <input id="file_upload" name="file_upload" type="file"
                                           multiple="false">
                                </div>
                                <div id="video" style="padding: 5px;"></div>
                                <input type="hidden" id="videoUrl" name="videoUrl" data-parsley-required="true"  value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="imageUrl" class="col-sm-2 control-label">上传视频封面图片</label>
                            <div class="col-sm-6">
                                <div id="imgQueue"></div>
                                <div>
                                    <input id="file_upload_img" name="file_upload" type="file"
                                           multiple="false">
                                </div>
                                <div id="img" style="padding: 5px;"></div>
                                <input type="hidden" id="imageUrl" name="imageUrl" value="">
                            </div>
                            <div class="col-sm-2" style="color: red;">建议尺寸：145*100</div>
                        </div>
                        <div class="form-group">
                            <label for="videoTitle" class="col-sm-2 control-label">视频标题</label>
                            <div class="col-sm-8">
                                <input type="text" id="videoTitle" class="form-control" name="videoTitle" data-parsley-required="true" placeholder="视频标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="delFlag" class="col-sm-2 control-label">是否上架</label>
                            <div class="col-sm-8 switcha">
                                <div class="mr15">
                                    <input type="checkbox" id="delFlag" name="delFlag"
                                           class="js-switch-blue" value="false" checked>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="videoDetails" class="col-sm-2 control-label">视频详情介绍</label>
                            <div class="col-sm-8">
                            <textarea id="videoDetails" name="videoDetails"
                                      style="width: 100%; height: 200px;"></textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="sort" class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-8">
                                <input type="text" id="sort" class="form-control" name="sort" data-parsley-required="true" value="0" placeholder="排序">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="price" class="col-sm-2 control-label">购买价格</label>
                            <div class="col-sm-8">
                                <input type="text" id="price" class="form-control" name="price" data-parsley-required="true" placeholder="购买价格">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3" style="margin: 20px;"></div>
            </form>
        </section>
    </div>
</div>
<script language="JavaScript">



    $(document).ready(function () {
        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    form.resetForm();
                    window.location.href='/store/video/cms';
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });


        //百度编辑器
        var ue= new baidu.editor.ui.Editor();
        ue.render('videoDetails');

        //form表单基础效果
        myForm.init();

        //上传视频
        $('#file_upload').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '请选择视频',
            'fileType': 'video/mp4,video/3GP,video/AVI',
            'fileSizeLimit': 1024000,
            'queueSizeLimit': 1,
            'overrideEvents': ['onDialogClose', 'onError'],
            'formData': {},
            'queueID': 'queue',
            'uploadScript': '${base}/open/ueditor/bd/uploadvideo',
            'onUploadComplete': function (file, data) {
            data = JSON.parse(data);
            if (data.state == 'SUCCESS') {
                Toast.success(data.msg);
                $("#video").html('<video src="'+data.url+'" controls="controls">\n' +
                    'your browser does not support the video tag\n' +
                    '</video>\n');
                $("#videoUrl").val(data.url);
            } else {
                clearVideo();
                Toast.error('服务器异常');
            }
        },
        'onDrop': function (file, fileDropCount) {
            clearVideo();
        },
            'onError': function (errorType, file) {
                if (file != 0) {
                    // var settings = $("#" + fileuploadId).uploadifive().settings;
                    switch (errorType) {
                        case 'UPLOAD_LIMIT_EXCEEDED':
                            Toast.error("上传的文件数量已经超出系统限制的1个文件！");
                            break;
                        case 'FILE_SIZE_LIMIT_EXCEEDED':
                            Toast.error("文件大小超出系统限制的1G大小！");
                            break;
                        case 'FORBIDDEN_FILE_TYPE':
                            Toast.error("文件类型不正确！");
                            break;
                    }
                }
            },
        'onClearQueue': function (queue) {
            clearVideo();
        },
        'onCancel': function () {
            clearVideo();
        }
    });

        //上传图片
        $('#file_upload_img').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '选择图片',
            'fileType': 'image/jpg,image/jpeg,image/png',
            'fileSizeLimit': 2048,
            'queueSizeLimit': 1,
            'overrideEvents': ['onDialogClose', 'onError'],
            'formData': {},
            'queueID': 'imgQueue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
            data = JSON.parse(data);
            if (data.code == 0) {
                Toast.success(data.msg);
                $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>");
                $("#imageUrl").val(data.data);
            } else {
                clearFile();
                Toast.error(data.msg);
            }
        },
        'onDrop': function (file, fileDropCount) {
            clearFile();
        },
        'onClearQueue': function (queue) {
            clearFile();
        },
            'onError': function (errorType, file) {
                if (file != 0) {
                    // var settings = $("#" + fileuploadId).uploadifive().settings;
                    switch (errorType) {
                        case 'UPLOAD_LIMIT_EXCEEDED':
                            Toast.error("上传的文件数量已经超出系统限制的1个文件！");
                            break;
                        case 'FILE_SIZE_LIMIT_EXCEEDED':
                            Toast.error("文件大小超出系统限制的2M大小！");
                            break;
                        case 'FORBIDDEN_FILE_TYPE':
                            Toast.error("文件类型不正确！");
                            break;
                    }
                }
            },
        'onCancel': function () {
            clearFile();
        }
    });


    });

    /**
     * 上传视频
     */
    function clearVideo() {
        $("#video").html("");
        $("#queue").html("");
        $("#videoUrl").val("");
    }

    /**
     * 上传图片
     */
    function clearFile() {
        $("#img").html("");
        $("#imgQueue").html("");
        $("#imageUrl").val("");
    }



</script>
<!--#}#-->


